#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteDuplicates(struct ListNode* head) {
    if (head == NULL || head->next == NULL)
        return head;
    struct ListNode* prev = head, * ptail = head->next;
    while (ptail)
    {
        while (ptail != NULL && prev->val == ptail->val)
        {
            ptail = ptail->next;
        }
        prev->next = ptail;
        prev = ptail;
        if (ptail == NULL)
            break;
        ptail = ptail->next;
    }
    return head;
}